package com.erp.gather.controller;
import com.erp.gather.service.IErpKakaCollectProductUploadTestTaskService;
import com.ruoyi.collect.api.domain.bo.ErpKakaCollectProductUploadTestTaskBo;
import com.ruoyi.collect.api.domain.vo.ErpKakaCollectProductUploadTestTaskVo;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 采集商品上传测试任务
 *
 * @author erp
 * @date 2023-05-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/collect/product/uploadTestTask")
public class ErpKakaCollectProductUploadTestTaskController extends BaseController {

    private final IErpKakaCollectProductUploadTestTaskService iErpKakaCollectProductUploadTestTaskService;

    /**
     * 查询采集商品上传测试任务列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpKakaCollectProductUploadTestTaskVo> list(ErpKakaCollectProductUploadTestTaskBo bo, PageQuery pageQuery) {
        return iErpKakaCollectProductUploadTestTaskService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取采集商品上传测试任务详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpKakaCollectProductUploadTestTaskVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpKakaCollectProductUploadTestTaskService.queryById(id));
    }

    /**
     * 新增采集商品上传测试任务
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpKakaCollectProductUploadTestTaskBo bo) {
        return toAjax(iErpKakaCollectProductUploadTestTaskService.insertByBo(bo));
    }

    /**
     * 修改采集商品上传测试任务
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpKakaCollectProductUploadTestTaskBo bo) {
        return toAjax(iErpKakaCollectProductUploadTestTaskService.updateByBo(bo));
    }

    /**
     * 删除采集商品上传测试任务
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpKakaCollectProductUploadTestTaskService.deleteWithValidByIds(Arrays.asList(ids), true));
    }



}
